package com.teamwhole.modules.act.service.ext;

import java.util.List;

import org.activiti.engine.identity.Group;
import org.activiti.engine.impl.persistence.entity.GroupEntityManager;
import org.springframework.stereotype.Service;

import com.google.common.collect.Lists;
import com.teamwhole.common.utils.SpringContextHolder;
import com.teamwhole.modules.act.utils.ActUtils;
import com.teamwhole.modules.sys.entity.User;
import com.teamwhole.modules.sys.service.UserService;

@Service
public class ActGroupEntityService extends GroupEntityManager {

	private UserService userService;

    @Override
    public List<Group> findGroupsByUser(String userId) {
        List<Group> list = Lists.newArrayList();
        User user = getUserService().findByLoginName(userId);
        /*
        if (user != null && user.getRoleList() != null){
            for (Role role : user.getRoleList()){
                list.add(ActUtils.toActivitiGroup(role));
            }
        }*/
		if (user != null && user.getDept() != null) {
			list.add(ActUtils.toActivitiGroup(user.getDept()));
		}
        return list;
    }
    
    public UserService getUserService() {
		if (userService == null){
			userService = SpringContextHolder.getBean(UserService.class);
		}
		return userService;
	}
	
}